include $(TOPDIR)/rules.mk

PKG_NAME:=qca-nss-drv
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2023-08-06
PKG_SOURCE_URL:=https://git.codelinaro.org/clo/qsdk/oss/lklm/nss-drv.git
PKG_SOURCE_VERSION:=1ab184034529539f61093184a67d4454cb3eb352
PKG_MIRROR_HASH:=6aa081c0853d3e3b6d78eee588a0967e540b2317d15aef3c3f6f7129925653f7

PKG_BUILD_PARALLEL:=1
PKG_FLAGS:=nonshared

PKG_CONFIG_DEPENDS:= \
	CONFIG_NSS_DRV_BRIDGE_ENABLE \
	CONFIG_NSS_DRV_C2C_ENABLE \
	CONFIG_NSS_DRV_CLMAP_ENABLE \
	CONFIG_NSS_DRV_CRYPTO_ENABLE \
	CONFIG_NSS_DRV_DMA_ENABLE \
	CONFIG_NSS_DRV_DTLS_ENABLE \
	CONFIG_NSS_DRV_EDMA_ENABLE \
	CONFIG_NSS_DRV_GRE_ENABLE \
	CONFIG_NSS_DRV_GRE_REDIR_ENABLE \
	CONFIG_NSS_DRV_GRE_TUNNEL_ENABLE \
	CONFIG_NSS_DRV_IGS_ENABLE \
	CONFIG_NSS_DRV_IPSEC_ENABLE \
	CONFIG_NSS_DRV_IPV4_REASM_ENABLE \
	CONFIG_NSS_DRV_IPV6_ENABLE \
	CONFIG_NSS_DRV_IPV6_REASM_ENABLE \
	CONFIG_NSS_DRV_L2TP_ENABLE \
	CONFIG_NSS_DRV_LAG_ENABLE \
	CONFIG_NSS_DRV_MAPT_ENABLE \
	CONFIG_NSS_DRV_MATCH_ENABLE \
	CONFIG_NSS_DRV_MIRROR_ENABLE \
	CONFIG_NSS_DRV_OAM_ENABLE \
	CONFIG_NSS_DRV_PORTID_ENABLE \
	CONFIG_NSS_DRV_PPE_ENABLE \
	CONFIG_NSS_DRV_PPPOE_ENABLE \
	CONFIG_NSS_DRV_PPTP_ENABLE \
	CONFIG_NSS_DRV_PVXLAN_ENABLE \
	CONFIG_NSS_DRV_QRFS_ENABLE \
	CONFIG_NSS_DRV_QVPN_ENABLE \
	CONFIG_NSS_DRV_OVPN_ENABLE \
	CONFIG_NSS_DRV_RMNET_ENABLE \
	CONFIG_NSS_DRV_SHAPER_ENABLE \
	CONFIG_NSS_DRV_SJACK_ENABLE \
	CONFIG_NSS_DRV_TLS_ENABLE \
	CONFIG_NSS_DRV_TRUSTSEC_ENABLE \
	CONFIG_NSS_DRV_TRUSTSEC_RX_ENABLE \
	CONFIG_NSS_DRV_TSTAMP_ENABLE \
	CONFIG_NSS_DRV_TUN6RD_ENABLE \
	CONFIG_NSS_DRV_TUNIPIP6_ENABLE \
	CONFIG_NSS_DRV_VIRT_IF_ENABLE \
	CONFIG_NSS_DRV_VLAN_ENABLE \
	CONFIG_NSS_DRV_VXLAN_ENABLE \
	CONFIG_NSS_DRV_WIFI_ENABLE \
	CONFIG_NSS_DRV_WIFI_EXT_VDEV_ENABLE \
	CONFIG_NSS_DRV_WIFI_MESH_ENABLE

include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk

NSS_CLIENTS_DIR:=$(TOPDIR)/qca/src/qca-nss-clients

define KernelPackage/qca-nss-drv
  SECTION:=kernel
  CATEGORY:=Kernel modules
  SUBMENU:=Network Devices
  DEPENDS:=@TARGET_qualcommax +kmod-qca-nss-dp
  TITLE:=Qualcomm NSS core driver
  FILES:=$(PKG_BUILD_DIR)/qca-nss-drv.ko
  AUTOLOAD:=$(call AutoLoad,32,qca-nss-drv)
endef

define KernelPackage/qca-nss-drv/config
	source "$(SOURCE)/Config.in"
endef

define KernelPackage/qca-nss-drv/install
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DIR) $(1)/etc/sysctl.d
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/hotplug.d/firmware
	$(INSTALL_DIR) $(1)/lib/debug

	$(INSTALL_BIN) ./files/qca-nss-drv.init $(1)/etc/init.d/qca-nss-drv
	$(INSTALL_BIN) ./files/qca-nss-drv.sysctl $(1)/etc/sysctl.d/qca-nss-drv.conf
	$(INSTALL_BIN) ./files/qca-nss-drv.conf $(1)/etc/config/nss
	$(INSTALL_BIN) ./files/qca-nss-drv.hotplug $(1)/etc/hotplug.d/firmware/10-qca-nss-fw
	$(INSTALL_BIN) ./files/qca-nss-drv.debug $(1)/lib/debug/qca-nss-drv
endef

define KernelPackage/qca-nss-drv/Description
This package contains a NSS driver for QCA chipset
endef

ifeq ($(CONFIG_TARGET_SUBTARGET), "ipq807x")
    SOC="ipq807x_64"
	subtarget:=$(CONFIG_TARGET_SUBTARGET)
else ifeq ($(CONFIG_TARGET_SUBTARGET), "ipq60xx")
    SOC="ipq60xx_64"
	subtarget:=$(CONFIG_TARGET_SUBTARGET)
endif

define Build/InstallDev
	mkdir -p $(1)/usr/include/qca-nss-drv
	$(CP) $(PKG_BUILD_DIR)/exports/* $(1)/usr/include/qca-nss-drv/
ifneq (, $(findstring $(subtarget), "ipq807x" "ipq60xx"))
	$(RM) $(1)/usr/include/qca-nss-drv/nss_ipsecmgr.h
	# $(INSTALL_DIR) $(1)/usr/include/qca-nss-clients
	# $(CP) $(NSS_CLIENTS_DIR)/exports/nss_ipsecmgr.h $(1)/usr/include/qca-nss-clients/.
endif
endef

EXTRA_CFLAGS+= -I$(STAGING_DIR)/usr/include/qca-nss-gmac \
			   -I$(STAGING_DIR)/usr/include/qca-nss-dp \
			   -I$(STAGING_DIR)/usr/include/qca-ssdk \
			   -Wno-unused-variable \
			   -Wno-error=unused-function

ifeq ($(BOARD),qualcommax)
EXTRA_CFLAGS+= -DNSS_MEM_PROFILE_MEDIUM
endif

DRV_MAKE_OPTS:=
ifndef CONFIG_NSS_DRV_BRIDGE_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_BRIDGE_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_C2C_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_C2C_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_CLMAP_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_CLMAP_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_CRYPTO_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_CRYPTO_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_DMA_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_DMA_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_DTLS_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_DTLS_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_EDMA_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_EDMA_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_GRE_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_GRE_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_GRE_REDIR_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_GRE_REDIR_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_GRE_TUNNEL_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_GRE_TUNNEL_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_IGS_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_IGS_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_IPSEC_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_IPSEC_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_IPV4_REASM_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_IPV4_REASM_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_IPV6_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_IPV6_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_IPV6_REASM_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_IPV6_REASM_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_L2TP_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_L2TP_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_LAG_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_LAG_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_MAPT_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_MAPT_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_MATCH_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_MATCH_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_MIRROR_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_MIRROR_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_OAM_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_OAM_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_PORTID_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_PORTID_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_PPE_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_PPE_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_PPPOE_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_PPPOE_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_PPTP_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_PPTP_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_PVXLAN_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_PVXLAN_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_QRFS_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_QRFS_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_QVPN_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_QVPN_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_OVPN_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_OVPN_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_RMNET_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_RMNET_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_SHAPER_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_SHAPER_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_SJACK_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_SJACK_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_TLS_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_TLS_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_TRUSTSEC_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_TRUSTSEC_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_TRUSTSEC_RX_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_TRUSTSEC_RX_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_TSTAMP_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_TSTAMP_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_TUN6RD_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_TUN6RD_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_TUNIPIP6_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_TUNIPIP6_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_VIRT_IF_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_VIRT_IF_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_VLAN_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_VLAN_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_VXLAN_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_VXLAN_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_WIFI_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_WIFI_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_WIFI_EXT_VDEV_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_WIFI_EXT_VDEV_ENABLE=n
endif
ifndef CONFIG_NSS_DRV_WIFI_MESH_ENABLE
   DRV_MAKE_OPTS += NSS_DRV_WIFI_MESH_ENABLE=n
endif

define Build/Configure
	$(LN) arch/nss_$(SOC).h $(PKG_BUILD_DIR)/exports/nss_arch.h
endef

define Build/Compile
	+$(MAKE) -C "$(LINUX_DIR)" $(strip $(DRV_MAKE_OPTS)) \
		CROSS_COMPILE="$(TARGET_CROSS)" \
		$(KERNEL_MAKE_FLAGS) \
		M="$(PKG_BUILD_DIR)" \
		EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
		SoC=$(SOC) \
		$(PKG_JOBS) \
		modules
endef

$(eval $(call KernelPackage,qca-nss-drv))
